<template>
  <div>
    <el-form :model="fince" label-width="110px" size="mini" :rules="rules">
      <el-form-item :label="$t('market.policy')">
        <el-select v-model="fince.fpolicyid" :disabled="isabled">
          <el-option
            v-for="item in billtype"
            :key="item.fid"
            :label="item.fname"
            :value="item.fid"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('market.entrydate')">
        <el-date-picker
          v-model.trim="fince.fentrydate"
          type="date"
          value-format="yyyy-MM-dd"
          :disabled="isabled"
          style="width: 163px"
        />
      </el-form-item>
      <el-form-item :label="$t('market.NoTax')">
        <el-input-number v-model="fince.fprice" controls-position="right" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.receiptsTax')">
        <el-input-number v-model="fince.ftaxprice" controls-position="right" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.costAmount')">
        <el-input-number v-model="fince.fcostprice" controls-position="right" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.costTax')">
        <el-input-number v-model="fince.ftaxcostprice" controls-position="right" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.soriginalprice')">
        <el-input v-model="fince.fassetsoriginalprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.lativedepprice')">
        <el-input v-model="fince.fcumulativedepprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.networthprice')">
        <el-input v-model="fince.fassetsnetworthprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.bookfprice')">
        <el-input v-model="fince.fbookfprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.sidualfprice')">
        <el-input v-model="fince.fexpectresidualfprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.usedate')" prop="fexpectusedate">
        <el-input v-model.trim="fince.fexpectusedate" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.currency2')">
        <el-input v-model="fince.fcurrencyname" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.depdate')">
        <el-input v-model="fince.fdepdate" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.depprice')">
        <el-input v-model="fince.fdepprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.outdepprice')">
        <el-input v-model="fince.fwithoutdepprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.mondepprice')">
        <el-input v-model="fince.feverymondepprice" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.nowdepmonths')" prop="fnowdepmonths">
        <el-input v-model="fince.fnowdepmonths" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.settleCurr')">
        <el-input v-model="fince.fsettlecurr" :disabled="isabled">
          <i
            slot="suffix"
            class="el-input__icon el-icon-search"
            @click="currencyVisiblit=true"
          />
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('market.exchangeType')">
        <el-input v-model="fince.fexchangetype" disabled />
      </el-form-item>
      <el-form-item :label="$t('market.exchangeRate')">
        <el-input-number v-model="fince.exchangerate" controls-position="right" :disabled="isabled" />
      </el-form-item>
      <el-form-item :label="$t('market.settleAmount')">
        <el-input-number
          v-model="fince.fsettleprice"
          :disabled="isabled"
          controls-position="right"
          @change="handelChange"
        />
      </el-form-item>
    </el-form>
    <!--结算币别列表-->
    <currency v-if="currencyVisiblit" @currency="currencyData" />
  </div>
</template>

<script>
import { queryRate, queryViewItem } from '@/api/marketManage/marketOrder'

export default {
  components: {
    currency: () => import('@/views/market/marketManage/createMarkerOrder/components/currency')
  },
  props: {
    fince: {
      type: Object,
      default: function() {
        return {
        }
      }
    },
    isabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currencyVisiblit: false,
      billtype: [],
      rules: {
        fexpectusedate: [
          { required: true, message: '使用期不能为空!', trigger: 'blur' }
        ],
        fnowdepmonths: [
          { required: true, message: '累计折旧期不能为空!', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.queryTBasBilltype()
  },
  methods: {
    // 会计凭证
    async queryTBasBilltype() {
      const { data: RES } = await queryViewItem({ viewName: 'SX_ASSETS_POLICY' })
      this.billtype = RES.list
      this.fince.fpolicyid = RES.list[0].fid
    }, // 结算币别
    currencyData(item) {
      if (item.fsettleCurrId) {
        this.fince.fsettlecurr = item.fsettleCurrIdName || item.fname
        this.fince.fsettlecurrid = item.fsettleCurrId || item.fcurrencyId
        this.queryCurrency(item.fsettleCurrId)
      }
      this.currencyVisiblit = false
    },
    // 选中币别获取汇率 类型
    queryCurrency(fsettlecurrid) {
      const DATA = {
        tocurrId: this.fince.fcurrencyid, // 本位币
        fromcurrId: fsettlecurrid, // 结算币别
        queryDate: this.fince.fentrydate
      }
      queryRate(DATA).then(res => {
        if (res.code === 0) {
          this.fince.fexchangetypeid = res.data.exchangeTypeId
          this.fince.fexchangetype = res.data.exchangeTypeName
          this.fince.exchangerate = res.data.exchangeRate
          this.handelChange()
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 监听结算金额
    handelChange() {
      this.fince.fprice = (this.fince.fsettleprice * this.fince.exchangerate).toFixed(2)
    }
  }
}
</script>

<style scoped lang="scss">
.el-input::v-deep .el-input__inner {
  height: 30px;
  line-height: 30px;
}
.el-form {
  display: flex;
  flex-wrap: wrap;
  .el-form-item {
    height: 30px !important;
    width: 275px;
    margin-bottom: 5px;
  }
}
</style>

